package com.woniu.bh.beautysalon.web.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.bh.beautysalon.model.dto.BeautysalonMoneyDto;
import com.woniu.bh.beautysalon.model.dto.DailyBudgetDto;
import com.woniu.bh.beautysalon.model.dto.QuarterIncomeDto;
import com.woniu.bh.beautysalon.model.params.BeautysalonPlatformflowsParam;
import com.woniu.bh.beautysalon.web.service.IPlatformFlowsService;
import com.woniu.bh.common.core.dto.ResultDto;
import com.woniu.bh.common.core.exception.ProjectException;
import com.woniu.bh.common.core.exception.ProjectExceptionResult;
import com.woniu.bh.common.core.util.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Daniel
 * @version 1.0.0
 * @ClassName PlatformFlowsController
 * @createTime 2020年10月15日 14:30:00
 */
@RestController
@RequestMapping("/wallet")
@Api(value = "美容馆接口", tags = "美容馆资金管理")
public class PlatformFlowsController {

    @Autowired
    private IPlatformFlowsService pfs;
    /**
     * @description: 日常流水
     * @param: request
     * @return: com.woniu.bh.common.core.dto.ResultDto
     */
    @PostMapping("/dailyBudget")
    @ApiOperation("日收入")
    public ResultDto dailyBudget(HttpServletRequest request) {
        Integer beautysalonId = Integer.parseInt(JwtUtil.parseToken(request.getHeader("X-Token")).get("beautysalonId").toString());
        try {
            DailyBudgetDto dailyBudgetDto = pfs.dailyBudget(beautysalonId);
            if (dailyBudgetDto != null) {
                return ResultDto.builder().success(true).code(1).message("操作成功").object(dailyBudgetDto).build();
            }
            return ResultDto.builder().success(false).code(ProjectExceptionResult.SYSTEM_ERROR.getCode()).message(ProjectExceptionResult.SYSTEM_ERROR.getMessage()).build();
        } catch (ProjectException p) {
            p.printStackTrace();
            return ResultDto.builder().success(false).code(ProjectExceptionResult.SYSTEM_ERROR.getCode()).message(ProjectExceptionResult.SYSTEM_ERROR.getMessage()).build();
        }

    }
    /**
     * @description:  季度收入
     * @param: request
     * @param: quarter
     * @return: com.woniu.bh.common.core.dto.ResultDto
     */
    @GetMapping("/quarterIncome/{quarter}")
    @ApiOperation("季度收入")
    public ResultDto quarterIncome(@PathVariable Integer quarter, HttpServletRequest request) {
        Integer beautysalonId = Integer.parseInt(JwtUtil.parseToken(request.getHeader("X-Token")).get("beautysalonId").toString());
        try {
            QuarterIncomeDto quarterIncome = pfs.quarterIncome(quarter,beautysalonId);
            if (quarterIncome!=null){
                return ResultDto.builder().success(true).code(1).message("执行成功").object(quarterIncome).build();
            }
            return ResultDto.builder().success(false).code(ProjectExceptionResult.SYSTEM_ERROR.getCode())
                    .message(ProjectExceptionResult.SYSTEM_ERROR.getMessage()).build();
        } catch (ProjectException p) {
            p.printStackTrace();
            return ResultDto.builder().success(false).code(ProjectExceptionResult.SYSTEM_ERROR.getCode())
                    .message(ProjectExceptionResult.SYSTEM_ERROR.getMessage()).build();
        }

    }
    /**
     * @description: 我的分成
     * @param: request
     * @return: com.woniu.bh.common.core.dto.ResultDto
     */
    @GetMapping("/getMyMoney")
    @ApiOperation("分页条件查询我的收入")
    public ResultDto getMyMoney(BeautysalonPlatformflowsParam param, HttpServletRequest request) {
        Integer beautysalonId = Integer.parseInt(JwtUtil.parseToken(request.getHeader("X-Token")).get("beautysalonId").toString());
        try {
            IPage<BeautysalonMoneyDto> iPage=pfs.getMyMoney(param,beautysalonId);
            return ResultDto.builder().success(true).code(1)
                    .message("查询成功").object(iPage).build();
        } catch (ProjectException p) {
            p.printStackTrace();
            return ResultDto.builder().success(false).code(ProjectExceptionResult.SYSTEM_ERROR.getCode())
                    .message(ProjectExceptionResult.SYSTEM_ERROR.getMessage()).build();
        }

    }
}

